<script lang="ts" setup>
import { onMounted, ref } from 'vue';
import { SimpleScrollbar } from '@sa/materials';
import { useRouterPush } from '@/hooks/common/router';
import { farmList } from '@/service/api/bigScreen';
import { useProjectStore } from '@/store/modules/project';
import { getFarmLabelListApi } from '@/service/api/businessApi';

const projectStore = useProjectStore();

const list = ref([]);
const projectId = projectStore.currentProject?.id;
const getFarmList = (id: string) => {
  farmList({ projectId, pageSize: 1000, labelId: id }).then(res => {
    if(res.data.data.length === 0) {
      list.value = []
    } else {
      list.value = res.data?.data;
    }
  });
};
const { routerPush } = useRouterPush();

const handleLinkDetails = (_id: any, name: string) => {
  routerPush(`/breedDetails?farmId=${_id}&projectId=${projectId}&name=${name}`);
};

onMounted(() => {
  getLabelList();
});

/* region ====== 获取分类列表 start */
const farmLabelList = ref([]);
const currentTag = ref();
const getLabelList = () => {
  getFarmLabelListApi({
    projectId: projectStore.currentProject?.id
  }).then(res => {
    if (res.data) {
      farmLabelList.value = res.data.data;
      currentTag.value = res.data.data[0].id;
      getFarmList(currentTag.value);
    }
  });
};
const tabChange = (key: string) => {
  getFarmList(key);
}
/* endregion === 获取分类列表 end */
</script>

<template>
  <div class="Card">
    <div class="card-header">
      <img src="../../../assets/imgs/breedAquatics/title_yclb@2x.png" alt="" />
    </div>
    <div class="ml-30px">
      <ATabs @change="tabChange" v-model:activeKey="currentTag" :tab-bar-style="{ color: '#fff', marginBottom: '4px', fontSize: '20px' }">
        <ATabPane v-for="item in farmLabelList" :key="item.id" :tab="item.label"></ATabPane>
      </ATabs>
      <div class="card-warp">
        <div class="warp-content">
          <div class="list-title list">
            <div>养殖池名称</div>
            <div>养殖品种</div>
          </div>
          <div>
            <SimpleScrollbar class="scroll" :step="0.2" hover="true">
              <div v-if="list.length > 0">
                <div
                  v-for="i in list"
                  :key="i.id"
                  class="list-content list item"
                  @click="handleLinkDetails(i.id, i.name)"
                >
                  <div>
                    {{ i.name }}
                  </div>
                  <div class="list-right">
                    <span>{{ i.remark }}</span>
                    <img src="../../../assets/imgs/breedAquatics/ic_more@2x.png" alt="" />
                  </div>
                </div>
              </div>
              <div v-else style="font-size: 16px; text-align: center; margin-top: 20px; color: #8dd8f2">
                暂无数据
              </div>

            </SimpleScrollbar>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.Card {
  width: 450px;
  height: 390px;
  background-image: url('@/assets/imgs/breedAquatics/img_left.png');
  background-size: 100% 100%;
  background-repeat: no-repeat;
  display: flex;
  flex-direction: column;
  .scroll {
    height: 236px;
    width: 100%;
    //margin: 100px auto;
    overflow: hidden;
  }
  .card-header {
    width: 100px;
    height: 50px;
    padding-top: 20px;
    margin-left: 20px;
  }

  .card-warp {
    flex: 1;
    width: 390px;
    .warp-content {
      height: 100%;

      .list-title {
        font-family: SourceHanSansCN, SourceHanSansCN;
        font-weight: 500;
        font-size: 16px;
        color: #8dd8f2;
      }

      .list-content {
        padding: 10px 10px;
        margin-top: 3px;
        font-family: SourceHanSansCN, SourceHanSansCN;
        font-weight: 400;
        font-size: 16px;
        color: #f1f1f1;
        background-size: 100% 100%;
        background-image: url('../../../assets/imgs/breedAquatics/bg_list_yclb_nor@2x.png');

        &:hover {
          background-image: url('../../../assets/imgs/breedAquatics/bg_list_yclb_sel@2x.png');
          color: #83fff1;
          cursor: pointer;
        }
      }

      .list {
        display: flex;
        justify-content: space-between;

        div {
          flex: 1;
        }

        .list-right {
          display: flex;
          align-items: center;
          justify-content: space-between;

          img {
            width: 20px;
            height: 20px;
          }
        }
      }
    }
  }
}
:deep(.ant-tabs .ant-tabs-tab) {
  font-size: 16px;
}
:deep(.ant-tabs-tab.ant-tabs-tab-active .ant-tabs-tab-btn) {
  color: #8dd8f2;
}
:deep(.ant-tabs .ant-tabs-ink-bar) {
  background: #8dd8f2;
}
</style>
